package test.yzx.pproject;

import android.app.Fragment;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;


public class MemoryFragment extends Fragment {

    private int number;

    public int getNumber() {
        return number;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(savedInstanceState != null){
            number = savedInstanceState.getInt("n");
        }else{
            number = (int) (Math.random()*999999);
        }
    }
    @Override
    public void onSaveInstanceState(Bundle outState) {
        outState.putInt("n", number);
        super.onSaveInstanceState(outState);
    }




    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(-1, -1);
        View view = new View(getActivity());
        view.setLayoutParams(lp);
        view.setBackgroundColor(Color.RED);
        view.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getActivity(), ""+number, Toast.LENGTH_SHORT).show();
            }
        });
        return view;
    }




}
